package handling.login.handler;

import client.MapleClient;
import org.apache.mina.core.session.IoSession;
import server.ServerProperties;
import tools.FileoutputUtil;
import tools.data.LittleEndianAccessor;
import tools.packet.LoginPacket;

public class DeleteCharHandler {

    private static boolean loginFailCount(MapleClient c) {
        c.loginAttempt = ((short) (c.loginAttempt + 1));

        return c.loginAttempt > 5;
    }

    public static void handlePacket(LittleEndianAccessor slea, MapleClient c) {
        /*
        if (!c.isGm()) {
            return;
        }
        */
        
        String Secondpw_Client = null;
        if (Secondpw_Client == null) {
            if (slea.readByte() > 0) { // Specific if user have second password or not
                Secondpw_Client = slea.readMapleAsciiString();
            }
            slea.readMapleAsciiString();
        }
        

        int Character_ID = slea.readInt();
        if (!c.login_Auth(Character_ID) || !c.isLoggedIn() || loginFailCount(c)) {
            System.err.println("there 36");
            c.getSession().close(true);
            return;
        }
        byte state = 0;
        
        if (c.getSecondPassword() != null) {
            if (Secondpw_Client == null) {
                System.err.println("there 44");
                c.getSession().close(true);
                return;
            }
            //if (!c.CheckSecondPassword(Secondpw_Client)) {
            //    state = 12;
            //}
        }

        if (state == 0) {
            state = (byte) c.deleteCharacter(Character_ID);
        }
        c.getSession().write(LoginPacket.deleteCharResponse(Character_ID, state));
    }
}

/* Location:           C:\Users\文炳\Desktop\CXFBY\114Maplewing.jar
 * Qualified Name:     handling.login.handler.DeleteCharHandler
 * JD-Core Version:    0.6.2
 */